package com.wsoft.system.controller;

import com.wsoft.response.ResponseResult;
import com.wsoft.system.query.account.PwdQuery;
import com.wsoft.system.query.account.StyleQuery;
import com.wsoft.system.service.ISysAccountService;
import com.wsoft.vo.config.LoginInfoRespVO;
import com.wsoft.vo.config.MultipleOrgRespVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 账号管理控制器
 *
 * @author zhonglj
 * @return
 * @date 2024-09-09 11:43
 **/
@RestController
@RequestMapping("/sys/account")
@Tag(name = "账号管理")
public class SysAccountController {

    @Resource
    private ISysAccountService sysAccountService;

    @Operation(summary = "用户个人信息", description = "登录成功后个人用户信息接口（个人信息、环境变量）")
    @GetMapping("/info")
    public ResponseResult<LoginInfoRespVO> getLoginInfo() {
        return ResponseResult.success(sysAccountService.getLoginInfo());
    }

    @Operation(summary = "修改密码", description = "修改密码")
    @PostMapping("/updatePwd")
    public ResponseResult updatePwd(@RequestBody PwdQuery query) {
        sysAccountService.updatePwd(query);
        return ResponseResult.success("[sys.account.updatePw.success]");
    }

    @Operation(summary = "修改个人风格", description = "修改个人风格")
    @PostMapping("/updateStyle")
    public ResponseResult updateStyle(@RequestBody StyleQuery query) {
        sysAccountService.updateStyle(query);
        return ResponseResult.success("[sys.account.updateStyle.success]");
    }

    @Operation(summary = "获取当前登录人多组织信息", description = "获取当前登录人多组织信息")
    @GetMapping("/multipleOrg")
    public ResponseResult<MultipleOrgRespVO> getMultipleOrg() {
        return ResponseResult.success(sysAccountService.getMultipleOrg());
    }

    @Operation(summary = "切换当前登录人登陆组织", description = "切换当前登录人登陆组织")
    @GetMapping("/changeLoginOrg")
    public ResponseResult changeLoginOrg(@RequestParam("orgId") Long orgId) {
        sysAccountService.changeLoginOrg(orgId);
        return ResponseResult.success("[account.success.changeLoginOrg]");
    }


    @Operation(summary = "根据组织类型查询当前登录人组织链的组织", description = "")
    @GetMapping("/getOrgIdByType")
    public ResponseResult getOrgIdByType(@RequestParam("type") String type) {
        return ResponseResult.success(sysAccountService.getOrgIdByType(type));
    }

    @Operation(summary = "获取账号信息", description = "")
    @GetMapping("/get")
    public ResponseResult get(@RequestParam("id") Long id) {
        return ResponseResult.success(sysAccountService.getById(id));
    }
}
